const resp = {
  message: 'success',
  code: 0,
  data: [{
    title: 'hello'
  }],
  name: {
    name1: 'wzy'
  },
  age: [[1, 2, 3], 2, 3]
}
// 实现get(resp,'message','data[0].title');

function get(obj, ...keys) {
  const res = [];
  for (let key of keys) {
    if (obj[key]) {
      res.push(obj[key])
    } else {
      let arr = key.split('.');
      console.log(arr);
      if (arr[0].indexOf('[') >= 0) {
        let index = arr[0].indexOf('[');
        console.log(index);
        let index2 = arr[0].indexOf(']');
        console.log(index2);
        let num = parseInt(arr[0].slice(index + 1, index2));
        console.log(num);
        res.push(obj[arr[0].slice(0, index)][num][arr[1]])
      } else {
        res.push(obj[arr[0]][arr[1]])
      }
    }
  }
  return res;
}

console.log(get(resp, 'message', 'data[0].title', 'name.name1'));
